package com.terabits.smartriver.netty.protocol;

import java.util.HashMap;
import java.util.Map;

public enum Type {

    UNKNOWN(-1),
    /*错误*/
    ERROR(144),
    /*服务器设置*/
    SERVER_SETTING(193),
    /*设置网络*/
    SET_WLAN(192),
    /*请求绑定*/
    BINDING(161),
    /*解除绑定*/
    REMOVE(162),
    /*控制命令*/
    CONTROL(163),
    /*获取状态*/
    GET_STATUS(164),
    /*上报状态*/
    UPLOAD_STATUS(165),
    /*获取数据*/
    GET_DATA(166),
    /*上报数据*/
    UPLOAD_DATA(167),
    /*上报数据*/
    FILTER_(168),
    /*上报数据*/
    FILTER_INVOKE(169),
    /*设备关机*/
    OFF(0x0000),
    LEVEL1(0x0001),
    LEVEL2(0x0002),
    LEVEL3(0x0003);
    final int type;


    Type(int cmd) {
        this.type = cmd;
    }

    public int getType() {
        return type;
    }


    public static class TypesEnum {
        private static final Map<Integer, Type> INT_TYPE_MAP;

        static {
            INT_TYPE_MAP = new HashMap<Integer, Type>();
            for (Type type : Type.values()) {
                INT_TYPE_MAP.put(type.getType(), type);
            }
        }

        public static Type fromInt(Integer i) {
            Type type = INT_TYPE_MAP.get(i);
            if (null == type) {
                type = Type.UNKNOWN;
            }
            return type;
        }
    }

}
